package com.cf.web.until;

import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.HashMap;

@Data
@AllArgsConstructor
public class R<T> {
    private Integer status;
    private String msg;
    private T data;

    /**
     * 1.status状态值：代表本次请求response的状态结果。
     */
    public final static int SUCCESS = 200;
    /**
     * 1.status状态值：代表本次请求response的状态结果。
     */
    public final static int FAILED = 400;


    private HashMap<String,Object> meta = new HashMap<>();

    private R<T> status(Integer status) { this.status = status; return this; }

    private R<T> msg(String msg) { this.msg = msg; return this;  }

    private R<T> data(T data) { this.data = data; return this;  }
    public R() {

    }
    public R(Integer status,String msg,T data) {
        meta.put("msg",msg);
        meta.put("status",status);
        this.data = data;
    }


    public R<T> meta(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
        return this;
    }

    public static <T> R<T> ok(Integer status, String msg, T data) {
        return  build(status,msg,data);
    }

    public static <T> R<T> error(Integer status, String msg) {
        return new R<T>().status(status).msg(msg);
    }

    public static <T> R<T> right(T data, String msg){
        return build(R.SUCCESS,msg,data);
    }
    public static <T> R<T> build(Integer status,String msg,T data){
        return new R(status,msg,data);
    }
}

